package logic

import (
	"context"
	"go.uber.org/zap"
	"homepage_srv/homepage"
	"homepage_srv/internal/svc"
	"homepage_srv/model"
	"smart-health-platforms/pkg"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetGoodSukLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetGoodSukLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetGoodSukLogic {
	return &GetGoodSukLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 查看单个sku
func (l *GetGoodSukLogic) GetGoodSuk(in *homepage.GetGoodSukRequest) (*homepage.GetGoodSukResponse, error) {
	var sku model.GoodSku
	sku.Id = uint32(in.SukId)
	err := sku.GetGoodSuk()
	if err != nil {
		pkg.Error("查看失败", zap.Error(err))
		return nil, err
	}
	return &homepage.GetGoodSukResponse{
		GoodId: int64(sku.GoodId),
		Color:  sku.Color,
		Stock:  int64(sku.Stock),
		Sales:  int64(sku.Sales),
		Price:  float32(sku.Price),
		Image:  sku.Image,
	}, nil
}
